import { devUrl, proUrl } from './config'
import { serviceGet, servicePost } from './serviceRequest'
import { request } from './request'
/**
 * 用户相关接口
 */

export interface HomeGETParams {
  isHot: number
  isTop: number
  page: number
  size: number
}
// 获取当前运行的环境
const env = import.meta.env.MODE
const baseUrl = env === 'development' ? devUrl.articleUrl : proUrl.articleUrl
const adminUrl = env === 'development' ? devUrl.adminUrl : proUrl.adminUrl
const userUrl = env === 'development' ? devUrl.baseUrl : proUrl.baseUrl
// home页面获取文章列表,  初次进入页面服务端渲染
export function getHomeList(data: HomeGETParams) {
  return servicePost(baseUrl + '/article/home/list', data)
}

// home页面获取文章列表,  客户端渲染
export function getHomeListClient(data: HomeGETParams) {
  return request.post(baseUrl + '/article/home/list', data)
}

// 服务端获取分类列表
export function getTagsList() {
  return serviceGet(adminUrl + '/category/list')
}
// 服务端获取文章详情
export function getArticleDetail(id: string) {
  return serviceGet(baseUrl + '/article/' + id)
}

// 客户端获取用户是否点赞，需要登录
export function getInteractionLikeStatus(params: { articleId: string; userId: string }) {
  return request.get(userUrl + '/api/article/getInteractionLikeStatus', { params: params })
}
// 客户端点赞取消点在，需要登录
export function postInteractionLike(data: { articleId: string; userId: string; num: number }) {
  return request.post(userUrl + '/api/article/like', data)
}
// 客户端获取用户是否收藏，需要登录
export function getInteractionCollectStatus(params: { articleId: string; userId: string }) {
  return request.get(userUrl + '/api/article/getInteractionFavoritesStatus', { params: params })
}
// 客户端收藏取消收藏，需要登录
export function postInteractionCollect(data: { articleId: string; userId: string; num: number }) {
  return request.post(userUrl + '/api/article/favorite', data)
}
// 客户端获取文章列表
export function getArticleListClient(data: any) {
  return request.get(baseUrl + '/article/list', { params: data })
}
// 客户端实现图片上传组件
export function uploadImage(data: FormData) {
  return request.post(userUrl + '/api/image/upload', data, {
    headers: { 'Content-Type': 'multipart/form-data' },
  })
}
// 获取我的搜藏文章
export function getMyFavoritesList(data: any) {
  return request.get(baseUrl + '/article/favorite/article/list', { params: data })
}
